import { memo, useState } from "react";
import chessClass from "./chessClass";

function initChess(chessmanList) {
  for (const [key, item] of chessmanList) {
    // 0 车 1 马 2 相 3 士 4 将 5 炮 6兵
    const nowConstructor = chessClass.get(
      chessClass.get("Chessman").chessNameList[item.chessId]
    );
    chessmanList.set(
      key,
      new nowConstructor(
        item.chessName,
        item.camp,
        item.x,
        item.y,
        item.key,
        item.chessId
      )
    );
  }
}

const MyChess = memo(function MyChess(data: any) {
  const { myKey, chessName, x, y, camp, isChecked, onChessClick } = data || {};
  const [test1, setT1] = useState({
    checkedChessman: null
  })
  return (
    <div
      className={`my-chess ${chessName} ${camp} ${isChecked ? "checked" : ""}`}
      style={{
        top: camp === "black" ? y * 100 + "px" : y * 100 + "px",
        left: x * 100 + "px",
        color: camp === "red" ? "red" : "black",
        fontWeight: 900,
      }}
      onClick={onChessClick}
    >
      {chessName}
    </div>
  );
});

export { initChess, MyChess };
